This application is based on applications Nos. 10-232392 and 10-232393 filed in Japan, the contents of which are hereby incorporated by reference.
1. Field of the Invention
The present invention relates to an image correction device, image correction method, and a computer program product in memory for image correction, capable of automatically correcting the brightness and contrast of the image and forming an image having ideal contrast and brightness.
2. Description of Related Art
Enhancing the contrast of the image, namely by processing that expands the lightness range at which the image is obtained and adjusts the contrast of a portion of the image is a widely known technique for improving the image quality.
When for instance, the image contrast is low, the lightness range acquired by the image is narrow. However, if the contrast could be raised by expanding the lightness range acquired by the image, from a high lightness image to an image with lower lightness, then an balanced image could be achieved and a shape difficult to see on a low contrast image could then easily be seen.
A method called histogram equalization is the conventional method used to enhance image contrast. In this method, a histogram is produced showing the lightness distribution of all pixels forming the original image, the accumulation curve of the histogram is converted into a modified mapping curve in which the pixel lightness values of the original image are converted into new lightness values and the image contrast then enhanced.
Since this method converts the lightness of pixels for the entire (all areas) original image into a new lightness with an identical modified mapping curve, then the locally varying contrast is likely to drop in portions. Consequently, when enhanced contrast over an entire image is needed, then contrast enhancement must be performed that matches those areas where contrast enhancement is needed.
A method called adaptive histogram equalization has therefore been proposed. In this method, the original image is subdivided into a plurality of rectangular areas, a histogram is produced showing the distribution status of lightness values for all pixels within each rectangular area, the histogram values are accumulated into a modified mapping curve, the modified mapping curve for each rectangular area found, and the lightness values of pixels within the rectangular area then converted into new lightness values. However, this method has the drawback that rectangular areas having over-enhanced contrast are prone to occur and the continuity of the contrast between adjacent rectangular areas becomes difficult to maintain.
In order to eliminate these drawbacks, values higher than a specified pixel distribution value are clipped from the histogram showing the distribution of pixel lightness values, the accumulated curve of values from the histogram is used as a modified mapping curve and by converting the lightness values of pixels within the rectangular area into new lightness values, image correction that limits the contrast enhancement can be performed.
Hereafter, the method for converting the pixel lightness by using the accumulated curve of values from the histogram as a modified mapping curve is explained while referring to FIG. 13 through FIG. 16. This conversion process is implemented by a CPU comprised of a image processing control device.
A view illustrating the scanning of the original image and the state when an original image A is stored in the image memory subdivided into a plurality of rectangular areas S1-Sn is shown in FIG. 13. The lightness for the total number of pixels in the area Sm is calculated and a histogram made. The histogram of FIG. 14, the vertical axis indicates the number of pixels and the horizontal axis indicates the pixel lightness. In FIG. 14, a line CL1 and a line CL2 indicate the clipping levels.
FIG. 15 is a histogram showing the histogram of FIG. 14 after being clipped with the clipping level CL1, the pixels greater than this clipping level are all distributed equally along the horizontal axis spanning the entire lightness. Distribution of pixels over the entire lightness values is achieved as a result of distributing pixels with a lightness greater than the clipping level, equally over the entire lightness.
Summing or accumulating the number of pixels of this histogram in the order of their lightness yields the accumulated curve shown in FIG. 16. This curve is called the modified mapping curve.
In the modified mapping curve of FIG. 16, the horizontal axis indicates the input pixel lightness level and the vertical axis indicates the output pixel lightness level. The output pixel lightness corresponding to the pixel lightness of the original image (input pixel lightness) is found according to the modified mapping curve, the pixel lightness of the original image is converted to the new pixel lightness and this conversion is performed on all pixels in the rectangular area Sm.
In the above process, the clipping level is determined by the lightness width (difference between the maximum and minimum lightness values) found from the histogram. Therefore, when the lightness width is narrow or in other words when the contrast is low, a high clipping level is set and when the lightness width is wide or in other words when the contrast is high, a low clipping level is set.
FIG. 17 shows a histogram level set at a low clipping level of CL2 (CL2 less than CL1) so that the pixel distribution over the entire lightness value is the results just as previously of equally distributing pixels with a lightness greater than the clipping level, over the total pixel lightness value.
In FIG. 18, a rectangular area Sm is made for the histogram shown in FIG. 17 and the sum of these respective histogram values is expressed in an accumulation curve or in other words, a modified mapping curve. Compared with the modified mapping curve with the high clipping level shown in FIG. 16, the inclination is not as steep. By using this modified mapping curve to perform lightness conversion of the original image pixels, the contrast enhancement of the image can be weakened.
A flowchart illustrating the above described processing is shown in FIG. 19. The original image is first subdivided into n pieces of rectangular areas S1-Sn (step P101). Next, a count value 1 is set in the counter (step P102) and a first rectangular data is loaded (step P103), the lightness per pixel is calculated, a histogram is made, and the lightness width is found (step P104). The clipping level is determined from the lightness width (step P105) and the histogramclipped (step P106). The pixel lightness of the histogram is summed, the accumulation curve is produced (step P107) to determine the brightness mapping curve matching that rectangular area.
Incrementing the counter (step P108) and a determination made that all processing of the subdivided image area is complete (step P109). If determined that the processing is not complete, the process returns to step P103 and processing of the next subdivided area is performed. When processing is complete, the lightness conversion (output lightness) is done from the pixel lightness (input lightness) for each rectangular area based on the modified mapping curve of each rectangular area, and lightness conversion is then performed for all pixels of the original image (step P110).
When the lightness of all pixels in the original image has been converted into new lightness values in the above processing, then image correction suppressing excessive contrast enhancement can be performed.
However, when the histogram is clipped to an appropriate clipping value and lightness conversion performed using the accumulated curve of the histogram as the modified mapping curve to correct the image contrast, a problem has been confirmed to occur in that the contrast is over-enhanced in light areas and dark areas in the image and also in that the improvement in brightness is insufficient in images such as high contrast images, back light images, image lightness is low in certain spots, image lightness is high in certain spots, etc. When for instance, correcting the image of a person whose face in back lighting appears dark, the facial portion may not appear very bright but if the contrast is over-enhanced then the image will appear unnatural.
1. In view of the above problems with the conventional art, this invention has the object of providing an image correction device and image correction method for automatically correcting the contrast and lightness of the original image and an image forming device capable of forming images with optimal contrast and brightness.
2. Another object of this invention is to provide an image correction device and image correction method for an image forming device capable of forming images with optimal contrast and lightness based on information relating to the original image scene and the average lightness of the image when correcting the contrast and lightness of the original image.
3. Still another object of this invention is to provide an image correction device and image correction method for automatically correcting the contrast and lightness of an area even when a portion of the lightness of the original image in that area is lighter or darker than the reference lightness and an image forming device capable of forming images with optimal contrast and brightness.
4. Yet another object of this invention is to provide computer program product in memory for image correction capable of forming an image with optimal contrast and lightness as well as to automatically correct the contrast and lightness of the original image.